<template>
  <ContentWrap>
    <!-- 搜索工作栏 -->
    <el-form
      class="-mb-15px"
      :model="queryParams"
      ref="queryFormRef"
      :inline="true"
      label-width="68px"
    >
      <el-form-item label="" prop="keyWord">
        <el-input placeholder="请输入内容" v-model.trim="keyWord">
          <template #prepend>
            <el-select v-model="kType" placeholder="请选择" class="!w-120px">
              <el-option label="网关名称" value="gatewayName" />
            </el-select>
          </template>
        </el-input>
      </el-form-item>
      <el-form-item label="在线状态" prop="onlineStatus">
        <el-select
          v-model="queryParams.onlineStatus"
          placeholder="在线状态"
          clearable
          class="!w-120px"
        >
          <el-option
            v-for="dict in onLineStateDictDatas"
            :key="parseInt(dict.value)"
            :label="dict.label"
            :value="parseInt(dict.value)"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
      </el-form-item>
    </el-form>
  </ContentWrap>

  <!-- 列表 -->
  <ContentWrap>
    <el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true">
      <el-table-column label="网关名称" align="left" prop="gatewayName" />
      <el-table-column label="网关类型：2无线3有线" align="center" prop="gatewayType" />
      <el-table-column label="在线状态" align="center" prop="onlineStatus">
        <template #default="scope">
            <dict-tag :type="DICT_TYPE.ONLINE_STATE" :value="scope.row.onlineStatus" />
        </template>
      </el-table-column>
      <el-table-column
        label="创建时间"
        align="center"
        prop="createTime"
        :formatter="dateFormatter"
        width="180px"
      />
    </el-table>
    <!-- 分页 -->
    <Pagination
      :total="total"
      v-model:page="queryParams.pageNo"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />
  </ContentWrap>
</template>

<script setup lang="ts">
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
import { dateFormatter } from '@/utils/formatTime'
import { TtlGatewayApi, TtlGatewayVO } from '@/api/zwsj/ttlgateway'

/** 网关管理 列表 */
defineOptions({ name: 'TtlGateway' })

const onLineStateDictDatas = getIntDictOptions(DICT_TYPE.ONLINE_STATE)
const loading = ref(true) // 列表的加载中
const list = ref<TtlGatewayVO[]>([]) // 列表的数据
// 列表的总页数
const total = ref(0)



const keyWord = ref('')
const kType = ref('gatewayName')
const queryParams = reactive({
  pageNo: 1,
  pageSize: 10,
  commId: undefined,
  gatewayName: '',
  onlineStatus: undefined,
})
const queryFormRef = ref() // 搜索的表单

/** 查询列表 */
const getList = async () => {
  loading.value = true
  try {
    queryParams.gatewayName= ''
    if (kType.value == 'gatewayName') {
      queryParams.gatewayName = keyWord.value
    }
    const data = await TtlGatewayApi.getTtlGatewayPage(queryParams)
    list.value = data.list
    total.value = data.total
  } finally {
    loading.value = false
  }
}

/** 搜索按钮操作 */
const handleQuery = () => {
  queryParams.pageNo = 1
  getList()
}

/** 初始化 **/
onMounted(() => {
  getList()
})
</script>